// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>

#define MOTOR_LF '1'
#define MOTOR_LB '2'
#define MOTOR_RF '3'
#define MOTOR_RB '4'
#define MOTOR_STOP '5'

#define UP '1'
#define DOWN '2'
#define LEFT '3'
#define RIGHT '4'
#define STOP '5'



AF_DCMotor motor(1);
AF_DCMotor motor_l(2);




void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  //Serial.println("Motor test!");

 // turn on motor
  motor.setSpeed(255); //min 0~255 max
  motor_l.setSpeed(255);
//  motor.run(RELEASE);
 // motor_l.run(RELEASE);
   motor.run(FORWARD);
   motor_l.run(FORWARD);
}

void loop() {
  uint8_t i;
  int num = 0;   // for incoming serial data
  
    if (Serial.available() > 0) {
                // read the incoming byte:
                num = Serial.read();
                Serial.println(num);
                set_direction(num);
        }
  

}


void set_direction (int dir)
{
 switch (dir) {
 
  case UP:
   motor.setSpeed(255); //min 0~255 max
   motor_l.setSpeed(255);
   delay(10);
    motor.run(FORWARD);
    motor_l.run(FORWARD);
    break;
   case DOWN:
   motor.setSpeed(255); //min 0~255 max
   motor_l.setSpeed(255);
   delay(10);
    motor.run(BACKWARD);
    motor_l.run(BACKWARD);
    break; 
   case LEFT:
   
     motor_l.setSpeed(100); 
     motor.setSpeed(255); //min 0~255 max
     delay(10);    
   //  motor.run(FORWARD);
    // motor_l.run(FORWARD);
    break;
   case RIGHT:
    motor.setSpeed(100); 
    motor_l.setSpeed(255); //min 0~255 max
    delay(10);
   // motor.run(FORWARD);
   // motor_l.run(FORWARD);
    break;   
  case STOP: 
     motor.run(RELEASE);
     motor_l.run(RELEASE);
    break;
 } 
}




/////////////////////////////////////////////////////////
void test_direction (int dir)
{
 switch (dir) {
  case MOTOR_LF:
    motor.run(RELEASE);
    motor_l.run(FORWARD);
    break;
   case MOTOR_LB:
    motor.run(RELEASE);
    motor_l.run(BACKWARD);
    break; 
   case MOTOR_RF:
    motor.run(FORWARD);
    motor_l.run(RELEASE);
    break;
   case MOTOR_RB:
    motor.run(BACKWARD);
    motor_l.run(RELEASE);
    break;   
  case MOTOR_STOP: 
     motor.run(RELEASE);
     motor_l.run(RELEASE);
    break;
 } 
}

 

  
  
  



